from Products.KnowledgeEngine.KERL.KERLObject import KERLObject

class CompiledKERL(KERLObject):
    
    __allow_access_to_unprotected_subobjects__ = 1
    
    _implements = KERLObject._implements + ('CompiledKERL',) 
    
    def __init__(self, compiled):
        self.compiled = compiled
    
    def toEnglish(self):
        """ Compiles this kerl statement into english """
    
        return self.compiled.toEnglish()
        
    def execute(self, assessment):
        """ Evaluates this statement """
                
        return self.compiled.execute( assessment )
        
    def getRaw(self):
        return self.compiled
    
    def toKERL( self ):
        return self.compiled.toKERL()
        
    def toSQL(self):
        return self.compiled.toSQL()
        
    #def toJavascript(self):
        #return sel
        
    def optimize(self, assessment, section=None):
        optimized = self.compiled.optimize( assessment, section )
        
        return OptimizedKERL( optimized )
    
    
class OptimizedKERL( CompiledKERL ):
            
    _implements = CompiledKERL._implements + ('OptimizedKERL',) 
    
    def toJavascript(self):
        return self.compiled.toJavascript()
        
        
        